package tsing.good_simple.no_static_call_static;

import tsing.good_simple.goodutil.RedisUtil;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * @Date 2024/7/16 17:08
 * @Author Tsing
 *
 * 对外提供的工具类
 *
 *
 *
 */

@Component
public class DemoUtil {



    private static RedisUtil redisUtil;

    /**
     * 静态注入
     */
    @Autowired
    public void setRedisUtil(RedisUtil redisUtil){
        this.redisUtil =redisUtil;
    }



    /**
     * 获取字典值的map<dict_value,dict_lable>集合
     * key： dict_type
     *
     *  K :字典code 0    => dict_value
     *  V  :  字典值  启用  => dict_label
     *  例如sys_dict:equity_channel_type
     * @return
     */
    public static Map<String,String> getRedisDictMap(String key){
        Map<String, String> collect = new HashMap<>();
        //从redis中获取字典值
        Object cacheObject = redisUtil.getCacheObject("sys_dict:"+key);
        if(cacheObject!=null){
            // 设置
/*            List<SysDictData> sysDictData = JSONArray.parseArray(JSONObject.toJSONString(cacheObject), SysDictData.class);
            //获取键值对
            collect = sysDictData.stream().collect(Collectors.toMap(SysDictData::getDictValue,SysDictData::getDictLabel));*/
        }
        return collect;
    }


}
